package com.seocoo.worker.user;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.seocoo.worker.R;
import com.seocoo.worker.base.UtilStatus;
import com.seocoo.worker.base.widget.AppToolBer;
import com.seocoo.worker.base.widget.EditTextCloseView;
import com.seocoo.worker.user.model.UserModel;
import com.sfh.lib.mvvm.LiveDataMatch;
import com.sfh.lib.ui.MVVMActivity;

/***
 * 修改昵称
 */
public class UserEditNickNameActivity extends MVVMActivity implements View.OnClickListener {


    private AppToolBer appToolBer;
    private EditTextCloseView etName;
    private TextView tvOk;

    public static void start(Activity context,String nikename, int requestCode) {
        Intent intent = new Intent(context, UserEditNickNameActivity.class);
        intent.putExtra("nikename",nikename);
        context.startActivityForResult(intent, requestCode);
    }


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_edit_nikename_activity);
        UtilStatus.initStatus(this, Color.WHITE);

        appToolBer = (AppToolBer) findViewById(R.id.appToolBer);
        etName = (EditTextCloseView) findViewById(R.id.et_name);
        tvOk = (TextView) findViewById(R.id.tv_ok);
        String nikename = getIntent().getStringExtra("nikename");
        etName.setText(nikename);
        tvOk.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        String name = etName.getText().toString().trim();
        if (TextUtils.isEmpty(name)) {
            showToast("请输入昵称！");
            return;
        }

        getViewModel(UserModel.class).editNickName(name);
    }


    @LiveDataMatch
    public void onEditNickNameSuccess() {
        setResult(RESULT_OK);
        finish();
    }

}
